package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.conf.oss.OssConfig;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.auto.FinishProject;
import com.fc.v2.model.auto.SysPosition;
import com.fc.v2.model.auto.SysPositionExample;
import com.fc.v2.model.auto.TsysUser;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.service.FinishProjectService;
import com.fc.v2.service.SysPositionService;
import com.fc.v2.shiro.util.ShiroUtils;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 社科联结项审核Controller
 * @ClassName: AuditFinishSKLController
 * @author Archie
 * @date 2021-11-08 11:54:59
 */
@Api(value = "单位结项审核")
@Controller
@RequestMapping("/AuditFinishSKLController")
public class AuditFinishSKLController extends BaseController{
	
	private String prefix = "gen/auditFinishSKL";
	
	@Autowired
	private FinishProjectService finishProjectService;

	@Autowired
	private SysPositionService sysPositionService;
	
	/**
	 * 结项审核申请页面展示
	 * @param model
	 * @return String
	 * @author Archie
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:finishProject:view")
    @OssConfig
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "单位结项审核", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@RequiresPermissions("gen:finishProject:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,FinishProject finishProject){
		PageInfo<FinishProject> page=finishProjectService.listSKL(tablepar,finishProject) ;
		return pageTable(page.getList(),page.getTotal());
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    @OssConfig
    public String add(ModelMap modelMap)
    {

        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "社科联结项审核新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@RequiresPermissions("gen:finishProject:add")
	@ResponseBody
	public AjaxResult add(FinishProject finishProject){
		int b=finishProjectService.insertSelective(finishProject);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 结项审核申请删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "结项审核申请删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@RequiresPermissions("gen:finishProject:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=finishProjectService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    @OssConfig
    public String edit(@PathVariable("id") String id, Model model)
    {
		model.addAttribute("FinishProject", finishProjectService.selectByPrimaryKey(id));

		//获取当前用户Id
		String userId = ShiroUtils.getUserId();
		TsysUser tsysUser = sysUserService.selectByPrimaryKey(userId);
		model.addAttribute("TsysUser", tsysUser);

		//获取单位
		String deptName = tsysUser.getDeptName();
		//获取单位管理模块信息
		SysPositionExample testExample=new SysPositionExample();
		testExample.createCriteria().andDeptNameEqualTo(deptName);
		List<SysPosition> sysPositionList = new ArrayList<>();
		sysPositionList = sysPositionService.selectByExample(testExample);
		SysPosition sysPosition = sysPositionList.get(0);
		model.addAttribute("SysPosition",sysPosition);

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "结项审核申请修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:finishProject:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FinishProject finishProject, @RequestParam("id") String id, HttpServletRequest request, HttpServletResponse response)
    {
        return toAjax(finishProjectService.updateByPrimaryKeySelectiveSkl(finishProject,id,request,response));
    }

    /**
	 * 修改状态
	 * @param record
	 * @return
	 */
    @PutMapping("/updateVisible")
	@ResponseBody
    public AjaxResult updateVisible(@RequestBody FinishProject finishProject){
		int i=finishProjectService.updateVisible(finishProject);
		return toAjax(i);
	}

}
